const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const UglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'test.js',
    // publicPath: 'dist/'   // 静态文件路径，超过配置的大小的图片打包位置，配置htmlWebpackPlugin后可以删掉
  },
  module: {
    rules: [
        {test: /\.css$/, use: [ 'style-loader', 'css-loader' ]},
        {test: /\.less$/, use: [
            {loader: "style-loader"},
            {loader: "css-loader" },
            {loader: "less-loader"}]},
        {test: /\.(png|jpg|gif|jpeg)$/, use: [{
            loader: 'url-loader',
            options: {
              limit: 17000,   // 图片小于17000k时，转化成base64显示，大于17000k时，打包成图片
              name: 'img/[name].[hash:8].[ext]'   // 大于17000k时，图片放到img目录下，文件名.8位哈希值.文件名后缀
            }
          }]},
        {test: /\.m?js$/,
          exclude: /(node_modules|bower_components)/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['es2015']
            }
          }
        },
        {test: /\.vue$/, use: ['vue-loader']}
      ]
  },
  resolve: {
    extensions: ['.js', '.css', '.vue'],   // 省略js,css,vue后缀
    alias: {
      'vue$': 'vue/dist/vue.esm.js' // 用 webpack 1 时需用 'vue/dist/vue.common.js'
    }
  },
  plugins: [
    new webpack.BannerPlugin('版权归徐珊所有'),
    new htmlWebpackPlugin({
      template: 'index.html'
    })
  ]
};